/**
 * @从函数返回一个指针
 *
 * @author	 wangshikun <wangshikun2010@gmail.com>
 * @copyright	(c) 2012 wangshikun <wangshikun2010@gmail.com>
 * @license	http://www.opensource.org/licenses/mit-license.php The MIT License
 * @package	default
 * @subpackage	default
 */

#include <stdio.h>

struct entry *findEntry(struct entry *listptr, int match);

struct entry {
	int value;
	struct entry *next;
};

int main(void) {
	struct entry n1, n2, n3;
	struct entry *listptr, *listStart = &n1;
	int search;

	n1.value = 100;
	n1.next = &n2;

	n2.value = 200;
	n2.next = &n3;

	n3.value = 300;
	n3.next = 0;

	printf("Enter value to locate: ");
	scanf("%d", &search);

	listptr = findEntry(listStrat, search);

	if (listptr != (struct entry *) 0) {
		printf("found %d\n", listptr->value);
	} else {
		printf("not found.\n");
	}

	return 0;
}

struct entry *findEntry(struct entry *listptr, int match) {
	while(listptr != (struct entry *) 0) {
		if (listptr->value == match) {
			return (listptr);
		} else {
			listptr = listptr->next;
		}
	}

	return (struct entry *) 0;
}
